package Demo09;

import Demo03.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.spi.http.HttpContext;
import java.util.ArrayList;
import java.util.List;

public class SetValStackData extends ActionSupport {

    private String name;

    public String getName() {
        return name;
    }

    private User user=new User();

    public User getUser() {
        return user;
    }


    private List<User> list=new ArrayList<>();

    public List<User> getList() {
        return list;
    }

    @Override
    //向值栈存取数据的方法
    public String execute() throws Exception {
        //1、使用值栈对象的set方法,存放map对象
        ActionContext context=ActionContext.getContext();
        ValueStack valueStack= context.getValueStack();
        valueStack.set("username","mary");

        //2、push方法,存放String对象
        valueStack.push("push");

        //3、生成get方法,存放Object对象
        name="3";

        //4、存放对象，生成get方法
        user.setUsername("asd");
        user.setPassword("adw");

        //5、存放list对象，生成get方法
        User user1=new User();
        user1.setUsername("qwe");
        user1.setPassword("456asd");
        list.add(user1);

        // # 获取域对象
        HttpServletRequest request=ServletActionContext.getRequest();
        request.setAttribute("user","欧阳锋");

        return SUCCESS;

    }
}
